package com.julius.design.suanfa.math;

/**
 * @author julius
 * @date 2021-10-18 上午 11:35
 * <p>
 *     数学中的阶乘demo
 *     N! = N * (N-1) * (N-2) * ... * 1
 * </p>
 */
public class FactorialDemo {


    /**
     * 计算n的阶乘
     * @param n
     * @return
     */
    public static int factorial(int n){
        /*
            N! = N * (N-1)!
            N-1 ! = N-1 * (N-2)!
         */
        //临界条件
        if(n == 0 || n == 1){
            return 1;
        }
        return n * factorial(n-1);
    }

    public static void main(String[] args) {
        int n = 3;
        System.out.println(factorial(10));
    }
}
